﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HomeNewsUserControl.ascx.cs"
    Inherits="JM.JCY.SharePointComponent.News.HomeNews.HomeNewsUserControl" %>

<script type="text/javascript">
    var timeInterval = 5000;    //5s = 5000ms
    var timeID = 0;

    $(document).ready(function () {
        $("#tdToggle1").click(function () {
            var div = document.getElementById("divToggleBC");
            if (div.style.display == "") {
                div.style.display = "none";
                $("#imgToggleBC").attr("src", "/_layouts/JM.JCY.Resource/images/toggle_expand.png");
                window.clearTimeout(timeID);
            }
            else {
                div.style.display = "";
                $("#imgToggleBC").attr("src", "/_layouts/JM.JCY.Resource/images/toggle_collapse.png");
                timeID = setInterval(changeBroadcast, timeInterval);
            }
        });

        turnPage(1);
        //timeID = setInterval(changeBroadcast, timeInterval);
    });

    $(document).ready(function () {
        $("#tdToggle2").click(function () {
            var div = document.getElementById("divToggleBC");
            if (div.style.display == "") {
                div.style.display = "none";
                $("#imgToggleBC").attr("src", "/_layouts/JM.JCY.Resource/images/toggle_expand.png");
                window.clearTimeout(timeID);
            }
            else {
                div.style.display = "";
                $("#imgToggleBC").attr("src", "/_layouts/JM.JCY.Resource/images/toggle_collapse.png");
                timeID = setInterval(changeBroadcast, timeInterval);
            }
        });

        turnPage(1);
        //timeID = setInterval(changeBroadcast, timeInterval);
    });

    function forwardClick() {
        window.clearTimeout(timeID)
        turnPageNext();
    }

    function backClick() {
        turnPagePrev();
    }

    function playpauseClick(sender) {
        var container = document.getElementById('content');
        var innerHTML = container.innerHTML;
        if (innerHTML.indexOf("/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png") >= 0) {
            container.innerHTML = innerHTML.replace("/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png", "/_layouts/JM.JCY.Resource/images/broadcast_webpart_play1.png");
            $("#imgURL").val("/_layouts/JM.JCY.Resource/images/broadcast_webpart_play1.png");
            window.clearTimeout(timeID);
        }
        else {
            container.innerHTML = innerHTML.replace("/_layouts/JM.JCY.Resource/images/broadcast_webpart_play1.png", "/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png");
            $("#imgURL").val("/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png");
            timeID = window.setInterval(function () { turnPageNext(); }, timeInterval);
        }
    }

    function changeBroadcast() {
        turnPageNext();
    }

    function RedirectToSearchNews(sender) {

        var URIScheme = "http://";
        var host = document.location.host;
        var url = URIScheme + host + "/NewsPages/SearchNews.aspx?Category=News";
        sender.href = url;
    }

    function RedirectToViewCurrentNews(sender, newsId) {

        var URIScheme = "http://";
        var host = document.location.host;
        var url = URIScheme + host + "/NewsPages/ViewNewsDetail.aspx?NewsId=" + newsId + "&Category=News";
        sender.href = url;
    }

    //Paging
    function turnPage(pageIndex) {
        $("#currIndex").val(pageIndex);
        //CallServer(currentIndex, 'content');
        CallServerSide();
    }

    function turnPagePrev() {
        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = 1;
        if (prevIndex > 1)
            currentIndex = prevIndex - 1;
        else
            currentIndex = $("#lastIndex").val();
        $("#currIndex").val(currentIndex);
        //CallServer(currentIndex, 'content');
        CallServerSide();
    }

    function turnPageNext() {
        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = $("#lastIndex").val();
        if (prevIndex < $("#lastIndex").val())
            currentIndex = prevIndex + 1;
        else
            currentIndex = 1;
        $("#currIndex").val(currentIndex);
        //CallServer(currentIndex, 'content');
        CallServerSide();
    }

    function CallServerSide() {
        var currentIndex = $("#currIndex").val();
        CallServer(currentIndex + "|" + $("#imgURL").val(), 'content');
    }

    function ReceiveCallback(arg, context) {
        var r = arg.split("|@|@|@");
        var container = document.getElementById(context);
        container.innerHTML = r[0];

        if (($("#lastIndex").val() == "" && r[1] != "") || $("#lastIndex").val() != r[1]) {
            $("#lastIndex").val(r[1]);
        }

        var container = document.getElementById('content');
        var innerHTML = container.innerHTML;
        if (innerHTML.indexOf("/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png") >= 0) {
            window.clearTimeout(timeID);
            timeID = window.setInterval(function () { turnPageNext(); }, timeInterval);
        }
        else {
            window.clearTimeout(timeID);
        }
    }
</script>
<div>
    <table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td>
                <table class="webpart" width="450" cellpadding="0" cellspacing="0">
                    <tr>
                        <th align="left" id="tdToggle1" class="title" width="50%" style="cursor: pointer">
                            <img src="/_layouts/JM.JCY.Resource/images/新闻小.png" width="24" />
                            新闻中心
                        </th>
                        <th id="tdToggle2"class="link" align="right" width="50%" style="cursor: pointer">
                         
                            <img class="toggle" id="imgToggleBC" src="/_layouts/JM.JCY.Resource/images/toggle_collapse.png" />
                        </th>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div id="divToggleBC">
                                <table width="100%" class="webpartContent">
                                    <tr>
                                        <td>
                                            <div id="content">
                                                <asp:DataList ID="dlNews" runat="server" RepeatColumns="1" OnItemDataBound="dlNews_ItemDataBound" Width="100%">
                                                    <ItemTemplate>
                                                        <table>
                                                            <tr>
                                                                <td valign="top" width="40%" rowspan="4">
                                                                    <asp:Image ID="imgPic" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' Width="144"
                                                                        Height="90" Style="margin-right: 20px;" />
                                                                </td>
                                                                <td valign="top" width="60%">
                                                                    <asp:Label ID="lblEffDate" runat="server" Text='<%# Eval("CREATED_TIME") %>'></asp:Label>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <asp:LinkButton ID="lbSubject" runat="server" class="linkTitle" Text='<%# PartSubString("Subject",Eval("Subject").ToString()) %>'
                                                                        OnClientClick='<%# String.Format("RedirectToViewCurrentNews({0},{1})","this",Eval("ID")) %>'></asp:LinkButton>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <asp:Label ID="lblSummary" runat="server" Text='<%# PartSubString("Summary",Eval("Summary").ToString()) %>'></asp:Label>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <asp:ImageButton ID="imgback" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/broadcast_webpart_backward1.png" Width="18"/>
                                                                    <asp:ImageButton ID="imgplaypause" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png" Width="18"/>
                                                                    <asp:ImageButton ID="imgforward" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/broadcast_webpart_forward1.png" Width="18"/>
                                                                    <asp:Label ID="lblSep" runat="server" Text='<%# Eval("Seq") %>'></asp:Label>
                                                                    of
                                                                    <asp:Label ID="lblCount" runat="server" Text='<%# Eval("Count") %>'></asp:Label>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </ItemTemplate>
                                                </asp:DataList>
                                            </div>
                                        </td>
                                    </tr>
                                      <tr><td colspan="2" align="right">   <asp:LinkButton ID="lbViewAllNew" runat="server" OnClientClick="RedirectToSearchNews(this)">更多...</asp:LinkButton></td></tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                
                    
                </table>
            </td>
        </tr>
    </table>
</div>

<input id="currIndex" type="text" value="1" style="display: none;" />
<input id="lastIndex" type="text" style="display: none;" />
<input id="imgURL" type="text" style="display: none;" value="/_layouts/JM.JCY.Resource/images/broadcast_webpart_pause1.png" />